import re
import requests
import csv

red_balls = {1: '20180820032902101600', 2: '20180820032902102212', 3: '20180820032902103176', 4: '20180820032902104855',
             5: '20180820032902105626',
             6: '20180820032902106488', 7: '20180820032902107839', 8: '20180820032902108769', 9: '20180820032902109210',
             10: '20180820032902110435',
             11: '20180820032902111316', 12: '20180820032902112341', 13: '20180820032902113809',
             14: '20180820032902114700', 15: '20180820032902115788',
             16: '20180820032902116463', 17: '20180820032902117946', 18: '20180820032902118438',
             19: '20180820032902119334', 20: '20180820032902120376',
             21: '20180820032902121785', 22: '20180820032902122325', 23: '20180820032902123264',
             24: '20180820032902124365', 25: '20180820032902125143',
             26: '20180820032902126490', 27: '20180820032902127951', 28: '20180820032902128235',
             29: '20180820032902129619', 30: '20180820032902130131',
             31: '20180820032902131493', 32: '20180820032902132554', 33: '20180820032902133669'}

blue_balls = {1: '20180820032902501531', 2: '20180820032902502184', 3: '20180820032902503880',
              4: '20180820032902504143', 5: '20180820032902505688',
              6: '20180820032902506270', 7: '20180820032902507239', 8: '20180820032902508548',
              9: '20180820032902509772', 10: '20180820032902510405',
              11: '20180820032902511276', 12: '20180820032902512964', 13: '20180820032902513798',
              14: '20180820032902514377', 15: '20180820032902515166',
              16: '20180820032902516449'}

dic = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"
}


page = 0
url = 'https://www.cjcp.com.cn/kaijiang/ssqmingxi_{}.html'.format(page)

resp = requests.get(url, headers=dic)
page_content = resp.text
obj = re.compile(r'<td><div class="kjjg_hm_bg">.*?<img src="js/kj_js_css/img/(?P<rb1>.*?).png'
                 r'.*?<img src="js/kj_js_css/img/(?P<rb2>.*?).png'
                 r'.*?<img src="js/kj_js_css/img/(?P<rb3>.*?).png'
                 r'.*?<img src="js/kj_js_css/img/(?P<rb4>.*?).png'
                 r'.*?<img src="js/kj_js_css/img/(?P<rb5>.*?).png'
                 r'.*?<img src="js/kj_js_css/img/(?P<rb6>.*?).png'
                 r'.*?<img src="js/kj_js_css/img/(?P<bb1>.*?).png" alt="" /></div></td>', re.S)
results = obj.finditer(page_content)
for i in results:
    
    print(i.group('rb1'))
    print(i.group('rb2'))
    print(i.group('rb3'))
    print(i.group('rb4'))
    print(i.group('rb5'))
    print(i.group('rb6'))
    print(i.group('bb1'))

resp.close()
